<?php

namespace app\admin\model;

use think\Model;

/**
 * GameListing
 */
class GameListing extends Model
{
    // 表名
    protected $name = 'game_listing';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    protected $append=['full_title'];
    public function stage(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\admin\model\GameStage::class, 'stage_id', 'id');
    }

    public function getFullTitleAttr(): string{
        $title = $this->stage->title.'-'.$this->title;
        if($this->stage->pid > 0){
            $stage = GameStage::where('id',$this->stage->pid)->find();
            $title = $stage->title.'-'.$title;
            if($stage->pid > 0){
                $stage = GameStage::where('id',$stage->pid)->find();
                $title = $stage->title.'-'.$title;
                if($stage->pid > 0){
                    $stage = GameStage::where('id',$stage->pid)->find();
                    $title = $stage->title.'-'.$title;
                    if($stage->pid > 0){
                        $stage = GameStage::where('id',$stage->pid)->find();
                        $title = $stage->title.'-'.$title;
                    }
                }
            }
        }
        return $title;
    }
}